package br.moneymonitor.adapters;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import br.moneymonitor.activity.R;
import br.moneymonitor.beans.Appointment;

public class AppointmentAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private List<Appointment> dividas;
	
	public AppointmentAdapter(Context context, List<Appointment> dividas) {
		this.mInflater = LayoutInflater.from(context);
		this.dividas = dividas;
		
	}
	@Override
	public int getCount() {
		if(dividas != null){
			return dividas.size();
		}
		return 0;
	}

	@Override
	public Object getItem(int position) {
		
		if (position > -1 && dividas != null){
			return dividas.get(position);
		}
		return null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Appointment divida = dividas.get(position);
		convertView = mInflater.inflate(R.layout.appointment_row, null);
		
		TextView textView = ((TextView)convertView.findViewById(R.id.descricao));
		String descricao = divida.getDescricao();
		textView.setText(descricao);
		TextView diasVencer = ((TextView)convertView.findViewById(R.id.diasVencimento));
		diasVencer.setText(divida.getDiasVencimento()+"\ndias");
		return convertView;
	}



}
